package com.rain.enums;

/**
 * 响应码枚举（统一返回状态码）
 *
 * @author Rain
 */
public enum ResponseCodeEnum {

    // ========== 成功 ==========
    CODE_200(200, "请求成功"),

    // ========== 客户端错误 ==========
    CODE_400(400, "请求参数错误"),
    CODE_401(401, "未授权，请登录"),
    CODE_403(403, "权限不足"),
    CODE_404(404, "请求地址不存在"),
    CODE_405(405, "请求方法不支持"),
    CODE_409(409, "资源冲突"),

    // ========== 服务端错误 ==========
    CODE_500(500, "服务器返回错误，请联系管理员"),
    CODE_501(501, "服务未实现"),
    CODE_502(502, "网关错误"),
    CODE_503(503, "服务不可用"),
    CODE_504(504, "网关超时"),

    // ========== 业务自定义错误 ==========
    CODE_600(600, "业务处理失败"),
    CODE_601(601, "信息已存在"),
    CODE_602(602, "信息不存在"),
    CODE_603(603, "数据校验失败"),
    CODE_604(604, "操作被拒绝"),
    CODE_605(605, "账户已被冻结");

    private final Integer code;
    private final String msg;

    /**
     * 私有构造函数
     */
    ResponseCodeEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 获取响应码
     */
    public Integer getCode() {
        return code;
    }

    /**
     * 获取响应消息
     */
    public String getMsg() {
        return msg;
    }

    // ================== toString ==================

    @Override
    public String toString() {
        return "ResponseCodeEnum{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                '}';
    }
}
